package com.langbricks.nlp.prs.printer;

import gate.*;
import gate.creole.ontology.Ontology;
import gate.jape.JapeException;
import gate.jape.RhsAction;

import java.util.Map;
import java.util.Collections;


/**
 * Created by IntelliJ IDEA.
 * User: user
 * Date: 25.09.2006
 * Time: 15:03:29
 */

public class TestRHSClass implements RhsAction {
    public void doit(Document doc, Map bindings,
                     AnnotationSet annotations, AnnotationSet inputAS,
                     AnnotationSet outputAS, Ontology ontology) throws JapeException {

        gate.AnnotationSet sequenceSet = ((gate.AnnotationSet) bindings.get("sequence"));
        gate.Annotation sequence = (gate.Annotation) sequenceSet.iterator().next();
        gate.AnnotationSet tmpTokenSet = annotations.getContained(sequence.getStartNode().getOffset(), sequence.getEndNode().getOffset());
        gate.AnnotationSet tokenSet = tmpTokenSet.get("Token");
        if (tokenSet != null && tokenSet.size() > 0) {
            java.util.ArrayList tokens = new java.util.ArrayList(tokenSet);
            Collections.sort(tokens, new gate.util.OffsetComparator());
            Annotation firstToken = (Annotation) tokens.iterator().next();
            String string = (String) firstToken.getFeatures().get("string");
            if ((string!=null&&string.equalsIgnoreCase("please"))||(string!=null&&string.equalsIgnoreCase("plz"))||(string!=null&&string.equalsIgnoreCase("pls"))) {
                sequence.getFeatures().put("pleaseKeywordStart", "yes");
            } else {
                sequence.getFeatures().put("pleaseKeywordStart", "no");
            }
        }
    }
}

